package com.hmy.contract.manager.finance;

import cn.hutool.json.JSONUtil;
import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.finance.api.bo.core.request.FinancialContractUpdateApiRequest;
import com.hmy.finance.api.client.FinancialContractUpdateFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author seven.qi 齐胜南
 * @version 1.0
 * @description
 * @date 2023/12/28 19:19
 */

@Component
@Slf4j
public class FinanceFeignClientManager {

    @Resource
    private FinancialContractUpdateFeignClient financialContractUpdateFeignClient;

    /**
     * 创建完成后回调财务系统，更新数据
     *
     * @param request 入参
     * @return {@link Boolean}
     */
    public Boolean updateStatementContractCreateInfo(FinancialContractUpdateApiRequest request) {
        log.info("FinanceFeignClientManager.updateStatementContractCreateInfo params:{}", JSONUtil.toJsonPrettyStr(request));
        FeignResult<Boolean> response = null;
        response = financialContractUpdateFeignClient.updateStatementContractCreateInfo(request);
        if (Objects.isNull(response)) {
            throw new HMYRuntimeException(502000007);
        }
        if (response.isFailed()) {
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        log.info("FinanceFeignClientManager.updateStatementContractCreateInfo response:{}", JSONUtil.toJsonPrettyStr(response));
        return response.getData();
    }

    /**
     * 签约完成后回调财务系统，更新数据
     *
     * @param request 入参
     * @return {@link Boolean}
     */
    public Boolean updateStatementContractConfirmInfo(FinancialContractUpdateApiRequest request) {
        log.info("FinanceFeignClientManager.updateStatementContractConfirmInfo params:{}", JSONUtil.toJsonPrettyStr(request));
        FeignResult<Boolean> response = null;
        response = financialContractUpdateFeignClient.updateStatementContractConfirmInfo(request);
        if (Objects.isNull(response)) {
            throw new HMYRuntimeException(502000007);
        }
        if (response.isFailed()) {
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        log.info("FinanceFeignClientManager.updateStatementContractConfirmInfo response:{}", JSONUtil.toJsonPrettyStr(response));
        return response.getData();
    }


}
